package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.listener.OnItemClickListener;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24 0024.
 * 现住查询列表标题右侧筛选按钮对话框适配器
 */

public class NowLiveSearchDialogAdapter extends BaseAdapter{

    private Context t;
    private List<String> mList;
    private  OnItemClickListener listener;
    private int index;//选中的位置下标
    public NowLiveSearchDialogAdapter(Context context, List<String> list, int index,OnItemClickListener listener){
        this.t=context;
        this.mList=list;
        this.index = index;
        this.listener=listener;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewHolder holder;
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        String room=mList.get(position);
        if(convertView == null){
            convertView = LayoutInflater.from(t).inflate(R.layout.divide_gridview_item,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder= (ViewHolder) convertView.getTag();
        holder.item.setText(room);
        if(index == position){
            holder.item.setChecked(true);
        }else{
            holder.item.setChecked(false);
        }
        holder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.onItemClick(position);
                }
            }
        });
        return convertView;
    }

    public class ViewHolder{
        CheckBox item;

        public ViewHolder(View view){
            item= (CheckBox) view.findViewById(R.id.cb);
        }
    }

}
